package example.dao.ibatis;

import java.util.ArrayList;
import java.util.List;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.template.SqlMapDaoTemplate;

import example.dao.IAccountDao;
import example.dao.PrimaryKeyGenerator;
import example.model.Account;

public class AccountIbatisDAO extends SqlMapDaoTemplate  implements IAccountDao {

	public AccountIbatisDAO(DaoManager daoManager) {
		super(daoManager);
	}

	public void create(Account account) {
		String primaryKey = account.getPrimaryKey();
		if (primaryKey == null) {
			primaryKey = PrimaryKeyGenerator.getUUID();
		}
		account.setPrimaryKey(primaryKey);
		insert("insert-Account", account);		
	}

	public void remove(String pk) {
		delete("delete-Account", pk);		
	}

	public Account retrieve(String pk) {
		Account account = (Account) queryForObject("getByPK-Account", pk);
		return account;
	}

	public void update(Account account) {
		update("update-Account", account);
		
	}

	public List<Account> selectAll() {
		List<Account> accounts = new ArrayList<Account>();
		accounts = queryForList("select-Account");
		return accounts;
		
		
		
	}
	
	
	
	
	
	


}
